# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: xguo

import collections

from coin.experimental.xguo.fruit.util.fee import get_fee_rate
from coin.exchange.base.kr_rest.currency import NativeCurrency
from coin.exchange.base.order_gateway import OrderSide
from coin.experimental.xguo.fruit.base.single_product import SingleProductPriceCalculator
from coin.experimental.xguo.fruit.util.util import VolatilityCalculator


class VolatilityPricer(object):
  def __init__(self, products):
    self._products = products
    self._price_calculators = {}
    self._volatility_calculators = {}
    self._timestamp = None

    for product in self._products:
      price_calculator = SingleProductPriceCalculator(product)
      self._price_calculators[product] = price_calculator
      self._volatility_calculators[product] = VolatilityCalculator(window_sec=10)

  def is_ready(self):
    return all(calculator.is_ready() for calculator in self._price_calculators.values())

  def update(self, book):
    self._timestamp = book.timestamp
    product = book.product
    price_calculator = self._price_calculators[product]
    price_calculator.update(book)
    midp = price_calculator.midp
    self._volatility_calculators[product].update(book.timestamp, midp)

  def gen_mm_orders(self, edge_bp=0):
    all_orders = collections.defaultdict(dict)
    return all_orders
